package com.jy.adscm.operation.mscyb.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.mscyb.bean.JqzzSettingDraw;
import com.jy.adscm.operation.mscyb.service.JqzzSettingDrawService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import com.jy.adscm.zltx.bean.JyDrawingList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-05-21
 */
@RestController
@RequestMapping("/adscm/operation/jqzz/jqzzSettingDraw")
public class JqzzSettingDrawController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    JqzzSettingDrawService jqzzSettingDrawService;

    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody List<JqzzSettingDraw> jqzzSettingDraws, HttpServletRequest request){
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        //删除之前的数据
        if (jqzzSettingDraws!=null&&jqzzSettingDraws.size()>0){
            //新增
            for (JqzzSettingDraw jqzzSettingDraw : jqzzSettingDraws) {
                jqzzSettingDrawService.insert(jqzzSettingDraw);
            }
        }
        return  new SimpleCoreResponse("200","新增成功",null);
    }
    @RequestMapping("delete/{id}")
    public  SimpleCoreResponse  selectBybid(@PathVariable Integer id) throws AdscmSystemException {
        boolean b = jqzzSettingDrawService.deleteById(id);
        return  new SimpleCoreResponse("200","查询成功",b);
    }

    @RequestMapping("selectBybid/{pid}")
    public  SimpleCoreResponse  selectBybid(@PathVariable String pid) throws AdscmSystemException {
        List<JqzzSettingDraw>   jqzzSettingDraws = jqzzSettingDrawService.selectJqzzSettingDrawsByPid(pid);
        return  new SimpleCoreResponse("200","查询成功",jqzzSettingDraws);
    }
    @RequestMapping("selectAll/{parentId}/{id}")
    public  SimpleCoreResponse  selectAll(@PathVariable Integer parentId,@PathVariable Integer id ) throws  AdscmSystemException{
        List<JyDrawingList>   jyDrawingLists = jqzzSettingDrawService.selectAll(parentId,id);
        return  new SimpleCoreResponse("200","查询成功",jyDrawingLists);
    }
}

